"""
Выводит полученные от польхователей сообщения в консоль.

Author: Milinuri Nirvalen
Ver: 1.4.1 (9)
"""

from chiori import Plugin
from chiori import Ui


p = Plugin(name='messages', backend='vk')


@p.eventHandler('before')
async def _(event,	ctx):
	u = Ui()
	color = u.lyellow
	prior = ''
	a = ''

	# цвет имени
	if event.get("level") == 10:
		color = u.cyan
	elif not event.get('level'):
		color = u.red

	if event.get('attachs'):
		for x in event.get('attachs'):
			a += f' {u.yellow}{x["type"]}{u.reset}'

	if event.get('reply'):
		a += f' {u.green}reply{u.reset}'

	if event.get('action'):
		a += f'\n> {u.green}{event.get("action")}{u.reset}'


	if event.get('to.is_chat'):
		place = f'#{event.get("to.id")}'
	else:
		place = f'ЛС'

	f_name = event.get('from.first_name')
	l_name = event.get('from.last_name')
	name = f'{color}{f_name} {l_name}{p.l.reset}'
	if event.get('from.username'):
		name += f' ({event.get("from.username")})'

	text_from = f'<{event.get("from.id")}> {name} из {place}'
	p.log(f'{text_from}:')
	u.form(f'{event.get("text", "")}{a}')
